package com.spzx.payment.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.payment.service.AlipayService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author: atguigu
 * @create: 2025-05-10 15:11
 */
@RestController
@RequestMapping("/alipay")
public class AlipayController extends BaseController {


    @Autowired
    private AlipayService alipayService;


    /**
     * 对接支付宝返回支付表单用于H5端支付
     * @param orderNo
     * @return
     */
    @Operation(summary = "对接支付宝返回支付表单用于H5端支付")
    @GetMapping("/submitAlipay/{orderNo}")
    public AjaxResult submitAlipay(@PathVariable String orderNo){
        //1.获取支付宝支付表单
        String payForm = alipayService.submitAlipay(orderNo);
        //2.响应支付宝支付表单，用于H5端支付
        return success(payForm);
    }


    /**
     * 支付宝回调:用户付款成功后，支付宝会通知商户系统支付结果
     * @param paramMap
     * @return
     */
    @Operation(summary = "用户付款成功后，支付宝会通知商户系统支付结果")
    @PostMapping("/callback/notify")
    public String paySuccessNotify(@RequestParam Map<String, String> paramMap){
        String result = alipayService.paySuccessNotify(paramMap);
        return result;
    }
}
